"use strict";

const { rspack } = require("@rspack/core");
// Require the rspack-chain module. This module exports a single
// constructor function for creating a configuration API.
const Config = require("rspack-chain").default;

// Instantiate the configuration with a new API
const config = new Config();

// Make configuration changes using the chain API.
// Every API call tracks a change to the stored configuration.
config
  // Interact with entry points
  .entry("index")
  .add("src/index.js")
  .end()
  // Modify output settings
  .output.path("dist")
  .filename("[name].bundle.js");

// Create named rules which can be modified later
config.module
  .rule("lint")
  .test(/\.js$/)
  .pre()
  .include.add("src")
  .end() /* end include */
  // Even create named uses (loaders)
  .use("eslint")
  .loader("eslint-loader")
  .options({
    rules: {
      semi: "off",
    },
  });

config.module
  .rule("compile")
  .test(/\.js$/)
  .include.add("src")
  .add("test")
  .end()
  // babel-loader
  .use("babel")
  .loader("babel-loader")
  .options({
    presets: [["@babel/preset-env", { modules: false }]],
  });

// // Create named plugins too!
// config
//   .plugin('clean').use(rspack.EvalSourceMapDevToolPlugin, [['dist'], { root: '/dir' }]);
console.dir(config.toConfig(), {
  depth: 10,
});

// // Export the completed configuration object to be consumed by rspack
module.exports = config.toConfig();
